/*
 * 
 */
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.PaintEvent;


public class Main {

	protected Shell shell;
	private Text text;
	private Text text_1;
	private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
	private int userType;

	/**
	 * Launch the application.
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			Main window = new Main();
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Open the window.
	 */
	public void open() {
		Display display = Display.getDefault();
		createContents();
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	/**
	 * Create contents of the window.
	 */
	protected void createContents() {
		shell = new Shell();
		shell.setSize(700, 500);
		
		shell.setMinimumSize(700, 500);
		shell.setText("SWT Application");
		
		//adding the image background
		
		final Display display = Display.getDefault();
		Canvas canvas = new Canvas(shell, SWT.NONE);
		canvas.addPaintListener(new PaintListener() {
			public void paintControl(PaintEvent e) {
				 org.eclipse.swt.graphics.Image image = new org.eclipse.swt.graphics.Image(display, "/Users/kennyha/Desktop/Eclipse Workplace/WelcomeScreen.png");
			        e.gc.drawImage(image, 10, 10);

			        image.dispose();
			}
		});
		
		canvas.setBounds(-15, -21, 754, 499);
		formToolkit.adapt(canvas);
		formToolkit.paintBordersFor(canvas);
		
		Label lblPassword = new Label(canvas, SWT.NONE);
		lblPassword.setBounds(206, 277, 69, 19);
		lblPassword.setText("Password");
		
		Label lblUserAccount = new Label(canvas, SWT.NONE);
		lblUserAccount.setBounds(193, 226, 69, 19);
		lblUserAccount.setText("User Name");
		
		Label lblDoctorManagementOffice = new Label(canvas, SWT.NONE);
		lblDoctorManagementOffice.setForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN));
		lblDoctorManagementOffice.setBounds(151, 104, 456, 45);
		lblDoctorManagementOffice.setFont(SWTResourceManager.getFont("Lucida Grande", 40, SWT.BOLD));
		lblDoctorManagementOffice.setAlignment(SWT.CENTER);
		lblDoctorManagementOffice.setText("Pokemon Center");
		
		text = new Text(canvas, SWT.BORDER);
		text.setBounds(267, 223, 110, 19);
		
		text_1 = new Text(canvas, SWT.BORDER);
		text_1.setBounds(267, 274, 110, 19);
		text_1.setEchoChar('*');
		
		Button btnSubmit = new Button(canvas, SWT.NONE);
		btnSubmit.setBounds(360, 344, 94, 24);
		/*
		btnSubmit.addKeyListener(new KeyAdapter() {
			@Override
			
			public void keyReleased(KeyEvent e) {
				if (e.keyCode == VK_ENTER);
				e.
			}
		});
		*/
		
				btnSubmit.addSelectionListener(new SelectionAdapter() {
					@Override
					public void widgetSelected(SelectionEvent e) {
					}
				});
				btnSubmit.setText("Log in");
		
		btnSubmit.addMouseListener(new MouseAdapter() {
			
			@Override
			public void mouseUp(MouseEvent e) {
				
				
				if(text.getText().equals("user")){
					userType = 1;
				}
				else if(text.getText().equals("admin"))
					userType = 2;
				
				else 
					userType = 0;
				
				
				Object window;
				//userType = 0;
				shell.close();
				//Validate user here
				switch(userType) {
				case 0:
					window = new NurseDoctor();
					((NurseDoctor)window).open();
					break;
				case 1: 
					window = new Trainer();
					((Trainer)window).open();
					break;
					
				case 2: 
					window = new AdminOnly();
					((AdminOnly)window).open();
					break;
				}
				
				
				
			}
		});
	}
}
